package com.example.materialcostsystembackend.repository;

import com.example.materialcostsystembackend.model.OrderItemDetail;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

@Repository
public interface OrderItemDetailRepository extends JpaRepository<OrderItemDetail, Long> {
    // 查询所有数据
    List<OrderItemDetail> findAll();

    // 查询数量大于 0 的数据
    List<OrderItemDetail> findByQuantityGreaterThan(BigDecimal quantity);
    List<OrderItemDetail> findByOrderSummary_OrderNumber(String orderNumber);
    @Query("SELECT COUNT(o) > 0 FROM OrderItemDetail o WHERE o.orderSummary.orderNumber = :orderNumber")
    boolean existsByOrderNumber(@Param("orderNumber") String orderNumber);
}